package com.changgou.search.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Sku;
import com.changgou.search.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @ClassName SkuController
 * @Author YPK
 * @Date 20:53 2019/11/15
 * @Version 2.1
 **/
@RestController
@RequestMapping("/search")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * @param searchMap
     * @Author: YPK
     * @Date: 2019/11/15  23:41
     * @Description TODO      检索
     * @return: java.util.Map<java.lang.String   ,   java.lang.Object>
     * @Version: 1.0
     **/
    @GetMapping
    public Map<String, Object> search(@RequestParam(required = false) Map<String, String> searchMap) {
        Map<String, Object> resultMap = skuInfoService.search(searchMap);
        return resultMap;
    }


    /**
     * @param
     * @Author: YPK
     * @Description TODO    数据导入 索引库
     * @return: com.changgou.entity.Result
     * @Date: 2019/11/15  21:20
     * @Version: 1.0
     **/
    @GetMapping("/import")
    public Result importData() {
        skuInfoService.importSkuInfoToEs();
        return new Result(true, StatusCode.OK, "数据导入成功");
    }
}